package com.cloudsigns.factorymanager2.produce.presenter;

import android.os.Handler;

import com.cloudsigns.factorymanager2.produce.bean.WorkPartFeedbackResponse;
import com.cloudsigns.factorymanager2.produce.iview.IProductFeedbackListView;
import com.cloudsigns.factorymanager2.produce.model.IProductFeedbackListModel;
import com.cloudsigns.factorymanager2.produce.model.ProductFeedbackListModel;

import java.util.List;

public class ProductFeedbackListPresenter {
    private IProductFeedbackListView view;
    private IProductFeedbackListModel model;
    private Handler handler = new Handler();

    public ProductFeedbackListPresenter(IProductFeedbackListView view) {
        this.view = view;
        this.model = new ProductFeedbackListModel();
    }

    public void productFeedbackList() {
        view.showLoading();

        model.productFeedbackList(new ProductFeedbackListModel.OnProductFeedbackListListener() {
            @Override
            public void getSuccessed(final List<WorkPartFeedbackResponse> workPartFeedbackResponseList) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getProductFeedbackListSuccessed(workPartFeedbackResponseList);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void getFailed(final String desc) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.showProductFeedbackListFailed(desc);
                        view.hideLoading();
                    }
                });
            }
        });
    }
}
